Skip to content

fix: solve #4364 — case-insensitive branch lookup for workspace creation - #4367

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
triage/issue-4364-25636005544
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
triage/issue-4364-25636005544

Conversation

@github-actions

@github-actions github-actions Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When the user creates a workspace targeting an existing remote branch and the typed casing doesn't match the canonical casing in git (e.g. picker shows claude/auto-balance-logo-sizing-1UFT7, but the value reaches the server as …-1uft7), planBranchSource silently forks a fresh branch from baseBranch instead of checking out the remote tip — and the next push opens a brand-new PR instead of continuing the existing one.

Root cause

resolveRef probes refs/heads/<input> and refs/remotes/origin/<input> via git rev-parse --verify, which is case-sensitive on case-sensitive filesystems. Anything that flattens the user's casing on the way in (cmdk's lowercased selected value, OS autocaps, retyping from memory) misses the existing ref, so planBranchSource returns usedExistingBranch: false and the worktree is created from main instead of the remote branch.

The fix

Added resolveRefCaseInsensitive in packages/host-service/src/runtime/git/refs.ts. It runs git for-each-ref over refs/heads/ and refs/remotes/origin/ and returns the canonical-cased ref when an input matches case-insensitively (local match wins over remote-tracking). planBranchSource calls it after the exact-case probe fails, before falling through to fresh-branch creation. The plan's branch is set to the canonical case so the resulting local branch and the workspace row both store the same casing as the remote.

Tests proving it

  • packages/host-service/test/integration/workspace-create-delete.integration.test.ts — two real-bare-remote scenarios:
    • exact-case typed branch tracks the existing remote tip (smoke check that the happy path still works)
    • lowercase-typed branch on a mixed-case remote — the regression. Before the fix, the worktree's HEAD equaled main. After the fix, it equals the remote tip.
  • packages/host-service/src/runtime/git/refs.test.ts — 7 unit tests for resolveRefCaseInsensitive (canonical case, local-wins precedence, origin/foo short-form, HEAD skipped, empty input, no-match → null).

Test plan

  • bun test packages/host-service/test/integration/workspace-create-delete.integration.test.ts — 12 pass
  • bun test packages/host-service/src/runtime/git/refs.test.ts — 19 pass
  • bun test packages/host-service/test/ packages/host-service/src/ — 583 pass, 0 fail
  • bun run --filter @superset/host-service typecheck — clean
  • bun run lint — clean

Closes #4364


Summary by cubic

Fixes incorrect workspace creation when branch casing differs from the remote, so we continue the existing remote branch instead of forking from base. Addresses #4364.

  • Bug Fixes
    • Added resolveRefCaseInsensitive to scan refs with git for-each-ref and return the canonical-cased match (local wins over remote; skips origin/HEAD; supports origin/foo input).
    • Updated planBranchSource to use this fallback after resolveRef fails and set the plan’s branch to the canonical case, ensuring the worktree tracks the remote tip.
    • Added integration and unit tests covering remote-only and mixed-case inputs to prevent regressions.

Written for commit 0e15c7f. Summary will update on new commits.

Branch names are case-sensitive in git, but the workspace-create input
pathway routinely flattens user-typed casing (cmdk's lowercased selected
value, OS autocaps, retyping a generated `claude/...-1UFT7` from memory).
When the input case didn't match the canonical case stored in git,
`planBranchSource` saw no match and silently forked a fresh branch from
the base, so the next push opened a brand-new PR instead of continuing
the existing one.

Add a `resolveRefCaseInsensitive` fallback that scans `git for-each-ref`
for a case-insensitive match (local wins over remote-tracking) and
returns the canonical-cased ref. `planBranchSource` calls it after the
exact-case `resolveRef` probe fails, before falling through to fresh-
branch creation.

Reproduced with a real bare-remote integration test in
`workspace-create-delete.integration.test.ts`: the worktree's HEAD now
points at the remote tip instead of the base branch's commit when the
typed branch case doesn't match the remote's casing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worktree creation can create a different branch than selected remote branch

1 participant